<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" title="选择议事室"></uni-navbar></view>
		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题"><u-input v-model="assembly.title" type="text" placeholder="请输入标题" /></u-form-item>
					<u-form-item class="form-item" label="县（区）">
						<u-input v-model="county" type="select" :select-open="countyShow" placeholder="请选择类型" @click="countyShow = true" />
						<u-select v-model="countyShow" :list="countyList" @confirm="countyConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="镇（街）">
						<u-input v-model="town" type="select" :select-open="townShow" placeholder="请选择类型" @click="showTown" />
						<u-select v-model="townShow" :list="townList" @confirm="townConfirm" value-name="orderNum" label-name="deptName"></u-select>
					</u-form-item>
				</u-form>
			</view>

			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>
		<view class="search-view">
			<u-search class="search-input" shape="square" bg-color="#fff" v-model="assembly.title" :show-filter="true" @search="search" @custom="show = !show"></u-search>
		</view>
		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of assemblyList" :key="item.id" @click="navTo(item)">
				<view class="info-title">{{ item.roomName }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.roomLeader }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" style="border: 0; color: #b8b8b8" v-if="item.createTime">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			flag_new: '1',
			region: '',
			nodeStatus: 0,
			topicNodeSea: '0',
			assemblyList: [],
			assembly: {
				title: '',
				townStreetSrea: '',
				countySea: '',
				clientCode: ''
			},

			roomName: '',
			loading: 'loadmore',
			show: false,
			countyShow: false,

			countyList: [
				{
					label: '请选择',
					value: ''
				},
				{
					label: '清江浦区',
					value: 320812
				},
				{
					label: '淮阴区',
					value: 320804
				},
				{
					label: '淮安区',
					value: 320803
				},
				{
					label: '洪泽区',
					value: 320813
				},
				{
					label: '涟水县',
					value: 320826
				},
				{
					label: '盱眙县',
					value: 320830
				},
				{
					label: '金湖县',
					value: 320831
				}
			],
			county: '',
			townShow: false,
			town: '',
			townList: []
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.topic) {
			this.topicNodeSea = option.topic;
			this.tabsCurrent = parseInt(option.topic) - 1;
		}
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		showTown() {
			if (this.county) {
				this.townShow = true;
			} else {
				this.$msg('请先选择县（区）');
			}
		},
		countyConfirm(e) {
			let data = e[0];
			this.county = data.value ? data.label : '';
			this.assembly.countySea = data.value ? data.value : '';
			this.town = '';
			this.assembly.townStreetSrea = '';
			if (this.county) {
				this.$request('/api/area/subList', { parentCode: data.value }).then((res) => {
					this.townList = [{ deptName: '请选择', orderNum: '' }];
					this.townList = this.townList.concat(res.data.lowerList);
				});
			}
		},
		townConfirm(e) {
			let data = e[0];
			this.town = data.value ? data.label : '';
			this.assembly.townStreetSrea = data.value ? data.value : '';
		},
		filter() {
			this.show = false;
			this.loadData('refresh');
		},
		resert() {
			this.assembly.title = '';
			this.county = '';
			this.assembly.countySea = '';
			this.town = '';
			this.assembly.townStreetSrea = '';
			this.loadData('refresh');
		},
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.assembly.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.region = this.userInfo.sysUser.remark2;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.topicNodeSea == 0) {
				this.topicNodeSea = '';
			}
			let data = {
				clientCode: this.clientCode,
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				leaderSea: '',
				discussRoomInfo: {
					roomName: this.roomName,
					roomAddress: ''
				},
				countySea: this.assembly.countySea,
				townStreetSea: this.assembly.townStreetSrea
			};
			this.$request('/xieshangyishi/discussroominfo/list', data).then((res) => {
				let count = 0;
				if (res.data) {
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.assemblyList = [];
					}
					try {
						this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
						this.pageNum = this.pageNum + 1;
						this.assemblyList = this.assemblyList.concat(res.data.records);
					} catch (e) {
						this.loading = 'nomore';
					}
					this.loaded = true;
					if (this.assemblyList.length <= 0) {
						this.loading = 'nodata';
					}
				} else {
					this.loading = 'nomore';
				}
			});
		},
		search(e) {
			this.assembly.title = e;
			this.roomName = e;
			this.loadData('refresh');
		},
		navTo(item) {
			uni.showModal({
				title: '温馨提示',
				content: '您确定要选择' + item.roomName + '?',
				success: function (res) {
					if (res.confirm) {
						uni.setStorageSync('roomMsg', item);
						uni.navigateBack();
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}
.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
